package com.xiu.travel.util;

import jakarta.annotation.Resource;
import jakarta.mail.MessagingException;
import jakarta.mail.internet.MimeMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;

/**
 * 发送邮件
 */
@Component
@Slf4j
public class MailUtil {

    @Resource
    JavaMailSender javaMailSender;


    public void sendSimpleMail(String from, String to,String subject, String content) throws MessagingException
    {
        // 简单邮件可以直接构建一个SimpleMailMessage对象进行配置，配置完成后，通过JavaMailSender将邮件发送出去。

        MimeMessage mailMessage = javaMailSender.createMimeMessage();
        MimeMessageHelper simpMsg = null;
        simpMsg = new MimeMessageHelper(mailMessage , true);
        simpMsg.setFrom("浅蓝喵喵喵"+"<"+from+">");
        simpMsg.setTo(to);
        simpMsg.setSubject(subject);
        simpMsg.setText(content,true);
        javaMailSender.send(mailMessage);

    }
}

